package cn.edu.neu.lab603.cloudeval.monitor

import java.util.concurrent.atomic.AtomicLong

import cn.edu.neu.lab603.cloudeval.CloudEval
import cn.edu.neu.lab603.cloudeval.entity.VirtualMachine
import cn.edu.neu.lab603.des.{SimMetric, SimMonitor}

/** 监控虚拟机被迁移的次数。
  *
  * Created by yfwz100 on 2016/11/3.
  */
class MigrationTimesMetric extends SimMonitor[CloudEval] with SimMetric[Long] {

  private val counter = new AtomicLong

  override def isMatch(context: CloudEval): Boolean = context.getCurrentTask.isInstanceOf[VirtualMachine.MigrationPreCopyEvent]

  override def before(context: CloudEval): Unit = {} // ignored

  override def after(context: CloudEval): Unit = {
    counter.incrementAndGet()
  }

  override def getCurrentValue: Long = counter.get()
}
